package com.zhuchaooasystem.entity;

import com.litesuits.orm.db.annotation.Column;
import com.litesuits.orm.db.annotation.NotNull;
import com.litesuits.orm.db.annotation.PrimaryKey;
import com.litesuits.orm.db.annotation.Table;
import com.litesuits.orm.db.enums.AssignType;
import com.zhuchaooasystem.utils.LiteDbUtils;

import java.util.List;

/**
 * @author yinsi
 */
@Table("UserInfo")
public class UserInfo {

    @PrimaryKey(AssignType.BY_MYSELF)
    @Column("id")
    private int memberId; //用户ID

    @Column("userName")
    @NotNull
    private String userName; //用户名

    @Column("password")
    private String password; //密码

    @Column("userPhone")
    private String userPhone;  //用户手机号

    @Column("userPostion")
    private String userPostion;  //用户职位

    @Column("RoleEmployee")
    private String RoleEmployee;  //用户角色

    @Column("UserDeparet")
    private String UserDeparet;  //部门

    public static UserInfo loginInfo;

    public static UserInfo getInstance() {
        List<UserInfo> list = LiteDbUtils.getInstance().query(UserInfo.class);
        //----
        if (list != null && list.size() > 0) {
            loginInfo = list.get(0);
        } else {
            loginInfo = new UserInfo();
        }
        return loginInfo;

    }

    public UserInfo() {
    }

    public UserInfo(int memberId, String userName, String password, String userPhone, String userPostion, String RoleEmployee,String UserDeparet) {
        this.memberId = memberId;
        this.userName = userName;
        this.password = password;
        this.userPhone = userPhone;
        this.userPostion = userPostion;
        this.RoleEmployee = RoleEmployee;
        this.UserDeparet=UserDeparet;
    }


    /**
     * 添加登录的用户到本地数据库
     *
     * @param id
     * @param userName
     * @param userPhone
     * @param userPostion
     * @param RoleEmployee
     */
    public static void saveLoginInfo(int id, String userName, String password, String userPhone, String userPostion, String RoleEmployee,String UserDeparet) {
        loginInfo = new UserInfo(id, userName, password, userPhone, userPostion, RoleEmployee,UserDeparet);
        //----
        List<UserInfo> list = LiteDbUtils.getInstance().query(UserInfo.class);
        if (list != null && list.size() > 0) {
            LiteDbUtils.getInstance().deleteAll(UserInfo.class);
        }
        LiteDbUtils.getInstance().save(loginInfo);
    }

    //更新数据
    public void updataIncome(UserInfo userInfo) {
        LiteDbUtils.getInstance().update(userInfo);
    }

    /**
     * 清空登录的用户
     */
    public static void clearLoginInfo() {
        //----
        LiteDbUtils.getInstance().deleteAll(UserInfo.class);
    }

    /**
     * 查询当前表内是否存在数据
     */
    public static boolean isNotEmpty() {
        //----
        List<UserInfo> list = LiteDbUtils.getInstance().query(UserInfo.class);
        if (list != null && list.size() > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 查询当前表内登录的用户
     */
    public static UserInfo getUserInfo() {
        //----
        List<UserInfo> list = LiteDbUtils.getInstance().query(UserInfo.class);
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }

    /**
     * 查询当前表内登录用户的member_id
     */
    public static int getPersonalPk() {
        //----
        List<UserInfo> list = LiteDbUtils.getInstance().query(UserInfo.class);
        if (list != null && list.size() > 0) {
            return list.get(0).getMemberId();
        } else {
            return 0;
        }
    }

    public static String getUName() {
        List<UserInfo> list = LiteDbUtils.getInstance().query(UserInfo.class);
        if (list != null && list.size() > 0) {
            return list.get(0).getUserName();
        } else {
            return "";
        }
    }

    public int getMemberId() {
        return memberId;
    }

    public void setMemberId(int memberId) {
        this.memberId = memberId;
    }

    public String getRoleEmployee() {
        return RoleEmployee;
    }

    public void setRoleEmployee(String roleEmployee) {
        RoleEmployee = roleEmployee;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getUserPostion() {
        return userPostion;
    }

    public void setUserPostion(String userPostion) {
        this.userPostion = userPostion;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUserDeparet() {
        return UserDeparet;
    }

    public void setUserDeparet(String userDeparet) {
        UserDeparet = userDeparet;
    }
}
